<%@page pageEncoding="utf-8"%>
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<jsp:include page="/layout/_css.jsp"/>
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap-table/1.12.1/bootstrap-table.css">
</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		<!-- <table id="table"></table> -->
		<div class="row">
			<div class="col-sm-12">
				  <div class="ibox float-e-margins">
				  	 <div class="ibox-title">
				  	 	<h5>学生列表</h5>
				  	 </div>
				  	 <div class="ibox-content">
		    			 <table id="table"></table>
				  	 	 <div class="btn btn-primary" onclick='deleteSelect()'>删除所选</div>
				  	 </div>
				  </div>
			</div>
		</div>
	</div>
</body>
<jsp:include page="/layout/_script.jsp"/>
<script src="https://cdn.bootcss.com/bootstrap-table/1.12.1/bootstrap-table.js"></script>
<script src="https://cdn.bootcss.com/bootstrap-table/1.12.1/locale/bootstrap-table-zh-CN.js"></script>
<script>
$('#table').bootstrapTable({
    url: '${ctx}/PlayerServlet/listAllJson',
    columns: [
    	{
    	checkbox:true
    	},{
        field: 'p_name',
        title: '姓名',
        sortable:true
    }, {
        field: 'p_car',
        title: '座驾'
    }, {
    	field: 'caozuo',
        title: '操作',
        formatter:function(v1,v2,v3){
        	return ['<a class="like" href="javascript:void(0)" title="Like">',
                '<i class="fa fa-pencil"></i>',
                '</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
                '<a class="remove" href="javascript:void(0)" title="Remove">',
                '<i class="glyphicon glyphicon-remove"></i>',
                '</a>'].join('');
        },
        events:'caocuoEvents'
    }],
    pagination:true,
    pageSize:5,
    pageList:[1,5,10],
    search:true,
    showRefresh:true,
    showColumns:true,
    clickToSelect:true,
    sidePagination:'server',
    rowStyle:function(v,index){
    	var classes = ['active', 'success', 'info', 'warning', 'danger'];
        if(index==3){
        	return {classes:'success'};
        }
        return {}; 
    }
});
window.caocuoEvents = {
        'click .like': function (e, value, row) {
            alert(row['p_id']);
        },
        'click .remove': function (e, value, row) {
        	if(confirm('是否删除')){
	        	 $.get('${ctx}/PlayerServlet/removeById',{'p_id':row['p_id']},function(r){
	        		 if(r){
	        			layer.msg('删除成功');
	        			 $('#table').bootstrapTable('refresh');
	        		 }else{
	        			 layer.msg('删除失败');
	        		 }
	        	 });
        	}
        }
    };

function deleteSelect(){
	arr = $('#table').bootstrapTable('getSelections');
	arr2 = [];
	for(i in arr){
		arr2.push(arr[i]['p_id']);
	}
	str = JSON.stringify(arr2);
	$.get('${ctx}/PlayerServlet/removeAll',{'pids':str},function(r){
		if(r){
			layer.msg("删除了"+r+"行数据");
		    $('#table').bootstrapTable('refresh');
		}else{
			layer.msg("删除失败");
		}
	});	
};
</script>
</html>